import path from 'path'
import express from 'express'
import cookieParser from 'cookie-parser'
import logger from 'morgan'
import cors from 'cors'
import indexRouter from '@/routes/index'
import usersRouter from '@/routes/users'

const app = express()

// 中间件
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')))
app.use(cors()) // 跨域

// 路由配置
app.use('/', indexRouter)
app.use('/users', usersRouter)

export default app
